package com.fzc.enums;

import java.util.Arrays;

/**
 * Created with com.fzc.enums.
 * User: fzc
 * Date: 2017/9/27
 * Time: 0:02
 * Info:
 */
public class TestDemo {

    public static void main(String[] args) {
        System.out.println(Color.getInstence(1));
        System.out.println(ColorEnum.RED);
        System.out.println(ColorEnum.RED.name() + "---" + ColorEnum.RED.ordinal());
        System.out.println(Arrays.toString(ColorEnum.values()));
    }
}



enum ColorEnum{
    RED,GREEN, BLUE
}

//多例
class Color{


    private static final Color RED = new Color("RED");
    private static final Color GREN = new Color("GREEN");
    private static final Color BLUE = new Color("BLUE");

    private String title;

    private Color(String title) {
        this.title = title;
    }

    @Override
    public String toString() {
        return "Color{" +
                "title='" + title + '\'' +
                '}';
    }

    public static Color getInstence(int ch) {
        switch (ch) {
            case 1 :
                return RED;
            case 2:
                return GREN;
            case 3:
                return BLUE;
            default:
                return null;
        }
    }


}